package LinkedListPackage;

import java.util.List;

/**
 * @author Lzm
 * @version 1.0
 */
public class swapPairs_ {

  public ListNode swapPairs(ListNode head) {
    if (head == null){
      return null;
    }
    ListNode dummyHead = new ListNode();
    dummyHead.next = head;
    ListNode temp = dummyHead;
    while(temp.next != null && temp.next.next != null){
      ListNode temp1 = temp.next;
      ListNode temp2 = temp.next.next;
      temp.next = temp2;
      temp1.next = temp2.next;
      temp2.next = temp1;
      temp = temp.next.next;
    }

    return dummyHead.next;
  }
}
